package com.jt.config;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;


/**
 * 集中模式的监听
 **/
@Component
public class RabbitmqLinsener {

    /**
     * 简单模式
     **/
    /*消费者1*/
    @RabbitListener(queues = RabbitmqConfig.name)
    public void xf1(String msg, Message message, Channel channel) {
        System.out.println("消费者1消费的消息有:" + msg);
    }

    /*消费者2*/
    @RabbitListener(queues = RabbitmqConfig.name)
    public void xf2(String msg, Message message, Channel channel) {
        System.out.println("消费者2消费的消息有:" + msg);
    }





    /**
     * 广播模式
     **/
    /*消费者1*/
    @RabbitListener(queues =RabbitmqConfig_fanout.QUEUE1)
    public void fanout1(String msg, Message message, Channel channel) {
        System.out.println("广播消费者1消费的消息有:" + msg);
    }

    /*消费者2*/
    @RabbitListener(queues =RabbitmqConfig_fanout.QUEUE2)
    public void fanout2(String msg, Message message, Channel channel) {
        System.out.println("广播消费者2消费的消息有:" + msg);
    }


    /**
     * direct。路由模式
     **/
    /*消费者1*/
    @RabbitListener(queues =RabbitmqConfig_RouterKey.QUEUE_DIRECT1)
    public void direct1(String msg, Message message, Channel channel) {
        System.out.println("路由消费者1消费的消息有:" + msg);
    }

    /*消费者2*/
    @RabbitListener(queues =RabbitmqConfig_RouterKey.QUEUE_DIRECT2)
    public void direct2(String msg, Message message, Channel channel) {
        System.out.println("路由消费者2消费的消息有:" + msg);
    }

}
